<template>
  <view class="skeletonWrap">
    <view v-if="loading" class="skeleton" :class="{ animate: animate }"  :style="{ justifyContent: flexType}">
			<!-- 轮播图 -->
			<view class="skeleton-imgTitle" ></view>
			<!-- banner -->
      <view class="skeleton-banner" >
			  <view class="banner-img"></view>
			  <view class="banner-title">
          <view class="title"></view>
          <view class="subtitle"></view>
        </view>
      </view>
      <!-- content -->
      <view class="skeleton-content" >
			  <view class="con-title"></view>
			  <view class="itemWrap">
          <view class="item">
            <view class="img"></view>
            <view class="title"></view>
          </view>
          <view class="item">
            <view class="img"></view>
            <view class="title"></view>
          </view>
          <view class="item">
            <view class="img"></view>
            <view class="title"></view>
          </view>
          <view class="item">
            <view class="img"></view>
            <view class="title"></view>
          </view>
          <view class="item">
            <view class="img"></view>
            <view class="title"></view>
          </view>
          <view class="item">
            <view class="img"></view>
            <view class="title"></view>
          </view>
          <view class="item">
            <view class="img"></view>
            <view class="title"></view>
          </view>
        </view>
      </view>
      <!-- content -->
      <view :style="{ height: '253rpx' }" class="skeleton-content" >
			  <view class="con-title"></view>
			  <view class="itemWrap">
          <view class="item">
            <view class="img"></view>
            <view class="title"></view>
          </view>
          <view class="item">
            <view class="img"></view>
            <view class="title"></view>
          </view>
          <view class="item">
            <view class="img"></view>
            <view class="title"></view>
          </view>
        </view>
      </view>
      <!-- content -->
      <view :style="{ height: '253rpx' }" class="skeleton-content" >
			  <view class="con-title"></view>
			  <view class="itemWrap">
          <view class="item">
            <view class="img"></view>
            <view class="title"></view>
          </view>
          <view class="item">
            <view class="img"></view>
            <view class="title"></view>
          </view>
          <view class="item">
            <view class="img"></view>
            <view class="title"></view>
          </view>
        </view>
      </view>
    </view>
    <view v-else><slot></slot></view>
  </view>
</template>

<script>
  const DEFAULT_ROW_WIDTH = '100%'
  const DEFAULT_LAST_ROW_WIDTH = '60%'

  export default {
    props: {
      loading: {
        type: Boolean,
        default: true,
      },
      imgTitle: {
        type: Boolean,
        default: false,
      },
      nameRow:{
        type: Number,
        default: 1,
      },
      flexType:{
        type: String,
        default: 'flex-start', // center	居中	√		space-between	两端对齐	√		space-around	子元素拉手分布	√		flex-start	居左		flex-end	居右
      },
      showAvatar: {
        type: Boolean,
        default: true,
      },
      avatarSize: {
        type: String,
        default: '50px',
      },
      avatarShape: {
        type: String,
        default: 'round', // square | round
      },
      showTitle: {
        type: Boolean,
        default: false,
      },
      titleWidth: {
        type: String,
        default: '40%',
      },
      row: {
        type: Number,
        default: 3,
      },
      animate: {
        type: Boolean,
        default: true,
      },
    },
    data() {
      return {}
    },
    computed: {
      rowList() {
        let list = []
        for (let i = 0; i < this.row; i++) {
          list.push({
            width: i === this.row - 1 && i !== 0 ? DEFAULT_LAST_ROW_WIDTH : DEFAULT_ROW_WIDTH,
          })
        }
        return list
      },
    },
  }
</script>

<style scoped lang="scss">
.skeletonWrap {
  height: 100%;
  width: 100%;
}

.skeleton {
  // margin: 16px;
  --bg-color: #E5E5E5;
  --box-bg-color: #F7F7F7;
  --row-height: 36rpx;
  --row-con-height: 26rpx;
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  .skeleton-imgTitle {
    border-radius: 20rpx 20rpx 0 0;
    background: var(--box-bg-color);
    margin: 0 32rpx;
    width: calc(100% - 64rpx);
    height: 190rpx;
  }
  .skeleton-banner {
    background: var(--box-bg-color);
    margin: 0 32rpx;
    width: calc(100% - 64rpx);
    box-sizing: border-box;
    height: 190rpx;
    border: 2px dotted rgba(148, 150, 152, 0.8);
    display: flex;
    justify-content: space-around;
    align-items: center;
    .banner-img {
      width: 120rpx;
      height: 120rpx;
      margin-left: 32rpx;
      margin-right: 20rpx;
      border-radius: 50%;
      background: var(--bg-color);
    }
    .banner-title {
      flex: 1;
      height: 100%;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: flex-start;
      .title {
        width: 458rpx;
        height: var(--row-height);
        background: var(--bg-color);
        border-radius: 18rpx;
        margin-bottom: 24rpx;
      }
      .subtitle {
        width: 458rpx;
        height: var(--row-con-height);
        background: var(--bg-color);
        border-radius: 13rpx;
      }
    }
  }
  .skeleton-content {
    margin: 0 32rpx;
    margin-top: 38rpx;
    width: calc(100% - 64rpx);
    height: 400rpx;
    background: #F7F7F7;
    border-radius: 20rpx;
    opacity: 0.86;
    .con-title {
      margin: 33rpx 32rpx 0;
      width: 140rpx;
      height: 36rpx;
      background: var(--bg-color);
      border-radius: 18rpx;
    }
    .itemWrap {
      margin-top: 39rpx;
      width: 100%;
      display: flex;
      align-items: center;
      flex-wrap: wrap;
      .item {
        width: 25%;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-direction: column;
        margin-bottom: 40rpx;
        .img {
          width: 64rpx;
          height: 64rpx;
          background: var(--bg-color);
          border-radius: 12rpx;
        }
        .title {
          width: 104rpx;
          height: var(--row-con-height);
          margin-top: 15rpx;
          background: var(--bg-color);
          border-radius: 13rpx;
        }
      }
    }
  }
}



.skeleton.animate {
  animation: skeleton-blink 1.2s ease-in-out infinite;
}

@keyframes skeleton-blink {
  0% {
    opacity: 1;
  }
  50% {
    opacity: 0.6;
  }
  100% {
    opacity: 1;
  }
}
</style>
